<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:pe="http://primefaces.org/ui/extensions">

    <h:body>

        <ui:composition template="/resources/template/template.xhtml">

            <ui:define name="content">
                <h:form>

                    <p:panel header="Department Stock Report by Batch" >

                        <h:panelGrid columns="6" >     

                            <p:commandButton value="Print" ajax="false" disabled="#{reportsStockVariant.recordedBillAfter.id eq null}" >
                                <p:printer target="gpBillPreview" ></p:printer>
                            </p:commandButton>
                            <p:commandButton ajax="false" value="Excel"  styleClass="noPrintButton" style="float: right;"
                                             disabled="#{reportsStockVariant.recordedBillAfter.id eq null}">
                                <pe:exporter type="xlsx" target="tbl" fileName="Category_report"  />
                            </p:commandButton>  
                            <p:commandButton ajax="false" value="Save Records"
                                            action="#{reportsStockVariant.saveRecordAfter()}"
                                             disabled="#{reportsStockVariant.recordedBillAfter.id ne null}"/>

                        </h:panelGrid>

                        <h:panelGroup id="gpBillPreview" styleClass="noBorder summeryBorder">
                            <p:dataTable id="tbl" value="#{reportsStockVariant.recordsAfter}" var="i"  >
                                <f:facet name="header">
                                    <h:outputLabel value="Note No : #{reportsStockVariant.recordedBillAfter.deptId}" rendered="#{reportsStockVariant.recordedBillAfter.id ne null}"/>
                                    <h:panelGrid columns="2">
                                        <h:outputLabel value="AFTER STOCK ADJUSTMENT"/> <br/>                   
                                        <h:panelGroup>
                                            <p:clock pattern="HH:mm:ss a - dd MMMM yyyy" mode="server"  rendered="#{reportsStockVariant.recordedBillAfter.id eq null}"/>  
                                            <h:outputLabel value="#{reportsStockVariant.recordedBillAfter.createdAt}" rendered="#{reportsStockVariant.recordedBillAfter.id ne null}"/>
                                        </h:panelGroup><br/>

                                        <h:outputLabel value="Department : #{reportsStockVariant.department.name} "/>   <br/>                                 
                                        <h:outputLabel value="Category : #{reportsStockVariant.category.name}"/>
                                    </h:panelGrid>                                                                   
                                </f:facet> 

                                <p:column headerText="Item">
                                    <f:facet name="header">
                                        <h:outputLabel value="Item"/>    
                                    </f:facet>
                                    <h:outputLabel value="#{i.item.name}" ></h:outputLabel>
                                </p:column>

                                <p:column headerText="Before Stock" style="text-align: right;" >
                                    <f:facet name="header">
                                        <h:outputLabel value="Before Stock"/>    
                                    </f:facet>
                                    <h:outputLabel value="#{i.referenceStockVariantBillItem.systemStock}"  >
                                    </h:outputLabel>                                  
                                </p:column>

                                <p:column headerText="After Stock" style="text-align: right;" >
                                    <f:facet name="header">
                                        <h:outputLabel value="After Stock"/>    
                                    </f:facet>
                                    <h:outputLabel value="#{i.systemStock}"  >
                                    </h:outputLabel>                                  
                                </p:column>

                                <p:column headerText="Variant Stock" style="text-align: right;" >
                                    <f:facet name="header">
                                        <h:outputLabel value="Variant Stock"/>    
                                    </f:facet>
                                    <h:outputLabel value="#{i.systemStock-i.referenceStockVariantBillItem.systemStock}"  >
                                    </h:outputLabel>                                  
                                </p:column>

                                <p:column headerText="Purchase Rate(Avg)" style="text-align: right;" >
                                    <f:facet name="header">
                                        <h:outputLabel value="Purchase Rate(Avg)"/>    
                                    </f:facet>
                                    <h:outputLabel  value="#{i.purchaseRate}"  >
                                        <f:convertNumber pattern="#,##0.00"/>
                                    </h:outputLabel>                                  
                                </p:column>

                                <p:column headerText="Before Total Value"  style="text-align: right;" >
                                    <f:facet name="header">
                                        <h:outputLabel value="Before Total Value"/>    
                                    </f:facet>
                                    <h:outputLabel value="#{i.referenceStockVariantBillItem.purchaseRate*i.referenceStockVariantBillItem.systemStock}"  >
                                        <f:convertNumber pattern="#,##0.00"/>
                                    </h:outputLabel>                                  
                                </p:column>

                                <p:column headerText="After Total Value"  style="text-align: right;" >
                                    <f:facet name="header">
                                        <h:outputLabel value="After Total Value"/>    
                                    </f:facet>
                                    <h:outputLabel  value="#{i.purchaseRate*i.systemStock}"  >
                                        <f:convertNumber pattern="#,##0.00"/>
                                    </h:outputLabel>                                  
                                </p:column>


                                <p:columnGroup type="footer">
                                    <p:row>
                                        <p:column footerText="Total Value" colspan="5"/>
                                        <p:column style="text-align: right;" >
                                            <f:facet name="footer">
                                                <h:outputLabel value="#{reportsStockVariant.systemStockValue}" rendered="#{reportsStockVariant.recordedBillAfter.id eq null}">
                                                    <f:convertNumber pattern="#,##0.00"/>
                                                </h:outputLabel>
                                                <h:outputLabel value="#{reportsStockVariant.recordedBillAfter.total}" rendered="#{reportsStockVariant.recordedBillAfter.id ne null}">
                                                    <f:convertNumber pattern="#,##0.00"/>
                                                </h:outputLabel>
                                            </f:facet>
                                        </p:column>
                                        <p:column style="text-align: right;" >
                                            <f:facet name="footer">
                                                <h:outputLabel value="#{reportsStockVariant.systemStockValueAfter}" rendered="#{reportsStockVariant.recordedBillAfter.id eq null}">
                                                    <f:convertNumber pattern="#,##0.00"/>
                                                </h:outputLabel>
                                                <h:outputLabel value="#{reportsStockVariant.recordedBillAfter.netTotal}" rendered="#{reportsStockVariant.recordedBillAfter.id ne null}">
                                                    <f:convertNumber pattern="#,##0.00"/>
                                                </h:outputLabel>
                                            </f:facet>
                                        </p:column>

                                    </p:row>
                                </p:columnGroup>

                            </p:dataTable>
                            <p:spacer height="25px" />
                            <p:panelGrid columns="2" style="min-width: 100%;">                             
                                <h:outputLabel value="________________________" /> 
                                <h:outputLabel value="________________________" />                             

                                <h:outputLabel value="Checked By" />                             
                                <h:outputLabel value="Pharmacist" />

                                <p:spacer height="25"/><p:spacer height="25"/>


                                <h:outputLabel value="________________________" />
                                <h:outputLabel value="________________________" />
                                <h:outputLabel value="Auditor" />  
                                <h:outputLabel value="Date" />

                            </p:panelGrid>



                        </h:panelGroup>


                        <!--</h:panelGroup>-->
                    </p:panel>
                </h:form>


            </ui:define>


        </ui:composition>

    </h:body>
</html>
